//
//  UIImage+RMaddWordToImage.m
//  水印
//
//  Created by lanou3g on 16/4/24.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "UIImage+RMaddWordToImage.h"

@implementation UIImage (RMaddWordToImage)

#pragma mark - 图片加文字
/*
 注释：在调用完该方法后会返回一张新的图片，这张图片就已经和将文字合成在上面了，而非是在图片上添加label
 */
// 为图片加上文字
+ (UIImage *)imageWithStringWaterMark:(NSString *)markString atImage:(UIImage *)image{
    if(image.size.width > 1440 || image.size.width > 1440) {
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(image.size.width * 0.5, image.size.height * 0.5), NO, 0.0);
        
        // 原图
        [image drawInRect: CGRectMake(0, 0, image.size.width * 0.5, image.size.height * 0.5)];
        // 文字颜色
        [[UIColor whiteColor] set];
        // 文字字体
        UIFont *font;
        if(image.size.width < [UIScreen mainScreen].applicationFrame.size.width) {
            //font = [UIFont boldSystemFontOfSize: 20];
            font = [UIFont fontWithName: @"迷你简菱心" size: kRealValue(20)];
        } else {
            //font = [UIFont boldSystemFontOfSize: 50];
            font = [UIFont fontWithName: @"迷你简菱心" size: kRealValue(60)];
        }
        // 文字位置
        CGPoint point = CGPointMake(image.size.width * 0.1 * 0.5, image.size.height * 0.5 * 0.8);
        // 水印文字
        [markString drawAtPoint: point withAttributes: @{NSFontAttributeName:font}];
        
    } else {
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(image.size.width * 0.7, image.size.height * 0.7), NO, 0.0);
        
        // 原图
        [image drawInRect: CGRectMake(0, 0, image.size.width * 0.7, image.size.height * 0.7)];
        // 文字颜色
        [[UIColor whiteColor] set];
        // 文字字体
        UIFont *font;
        if(image.size.width < [UIScreen mainScreen].applicationFrame.size.width) {
            //font = [UIFont boldSystemFontOfSize: 20];
            font = [UIFont fontWithName: @"迷你简菱心" size: kRealValue(20)];
        } else {
            //font = [UIFont boldSystemFontOfSize: 50];
            font = [UIFont fontWithName: @"迷你简菱心" size: kRealValue(60)];
        }
        // 文字位置
        CGPoint point = CGPointMake(image.size.width * 0.1 * 0.7, image.size.height * 0.7 * 0.8);

    }
    
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    NSLog(@"%@",newImage);
    
    return newImage;

}





@end

